#!/bin/bash

app_name=$1

if [[ $app_name = "" ]];
then
  echo "未指定服务名称，退出"
  exit 0
fi

self_dir=$(dirname $(readlink -f "$0"))  # 当前脚本的绝对路径
work_dir=$(dirname $(dirname "$self_dir"))  # 工作目录，相当于：../../
service_dir="$work_dir/service/running/$app_name"

cd "$service_dir"
# 如果已经启动，则重启
if [[ $(docker ps --format "{{.Names}}" | grep $app_name |wc -l) -gt 0 ]];
then
    echo "已启动，重启服务"
    docker restart $app_name
else
    echo "未启动，现在启动"
    docker compose -f "$service_dir/docker-compose.yaml" up -d
fi;

# 查看日志
docker logs -f --tail 200 $app_name
